extends Reference
class_name ActorM
var w_lvl=W.w(1)
var n_max_hp=Numeral.new(100)
var n_atk=Numeral.new(10)
var n_def=Numeral.new(10)
var n_attackSpeed=Numeral.new(100)
var n_attackRange=Numeral.new(200)
var n_moveSpeed=Numeral.new(100)
var w_hp=W.w(n_max_hp.value)
var w_experience=W.w(0)
var w_regionId=W.w(1)
var w_pre_experience=W.w(0)
var w_next_experience=W.w(100000000)


##属性
var lvl setget set_lvl,get_lvl  #等级 目前只有player的等级有用
var max_hp setget ,get_max_hp
var atk setget ,get_atk
var def setget ,get_def
var hp setget set_hp,get_hp #速度
var attackSpeed setget ,get_attackSpeed
var attackRange setget ,get_attackRange
var moveSpeed setget ,get_moveSpeed
var type='player' # payer enemy npc 类型
var camp='player'  # player  enemy
var experience setget set_experience,get_experience
var pre_experience setget set_pre_experience,get_pre_experience #上一级的经验
var next_experience setget set_next_experience,get_next_experience #到达下一级的经验
var regionId setget set_regionId,get_regionId #地区 区分地图 不同地区的人互不干扰
var killExp=0 #击杀后获得的经验 怪物用
var skin="" #怪物图片位置
var buffs=[] #buff列表
func _init():
	n_max_hp.w_value.onChange(self,'_max_hp_change')
	w_lvl.onChange(self,'_lvl_change')
	w_experience.onChange(self,'_experience_change')
	pass
func get_oppentCamp():
	if camp=='player':
		return 'enemy'
	else:
		return 'player'
func _max_hp_change(value,pre):
	var v=w_hp.value
	v=clamp(int(float(v)/pre*value),1,value)
	w_hp.value=v
func set_lvl(v):
	w_lvl.value=v
func get_lvl():
	return w_lvl.value
func _lvl_change(cur,pre):
	if type=='player':
		var obj=G.get_playerLvlData(cur)
		self.max_hp=obj.max_hp
		self.atk=obj.atk
		self.def=obj.def
		self.next_experience=obj.next_experience
		self.pre_experience=max(G.expForLevel(cur),0)
	pass
func get_max_hp():
	return n_max_hp.value
func get_atk():
	return n_atk.value
func get_def():
	return n_def.value
func set_hp(v):
	w_hp.value=v
func get_hp():
	return w_hp.value
func get_attackSpeed():
	return n_attackSpeed.value
func get_attackRange():
	return n_attackRange.value
func get_moveSpeed():
	return n_moveSpeed.value
func set_experience(v):
	w_experience.value=v
func get_experience():
	return w_experience.value
func set_regionId(v):
	w_regionId.value=v
func get_regionId():
	return w_regionId.value
func _experience_change(cur,pre):
	while cur>=w_next_experience.value:
		self.lvl+=1 #升级
func get_pre_experience():
	return w_pre_experience.value
func set_pre_experience(v):
	w_pre_experience.value=v
func get_next_experience():
	return w_next_experience.value
func set_next_experience(v):
	w_next_experience.value=v
func dispose():
	var arr=[n_max_hp,
		n_atk,
		n_def,
		w_hp,
		n_attackSpeed,
		w_lvl,
		w_experience,
		w_regionId,
		n_moveSpeed,
		n_attackRange
		]
	for n in arr:
		n.dispose()
